<%--
  Created by IntelliJ IDEA.
  User: lml
  Date: 2022/10/13
  Time: 16:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册</title>
</head>
<script type="text/javascript" src="static/jquery-3.6.1.min.js"></script>
<script>
    function checkUserName(name){
        var name=name;
        $.ajax({
            type:"post",
            url:"checkUserName",
            data:{name:name},
            success: function (data) {
                alert(data)
                if (data=="0"){
                    alert(1111)
                  document.getElementById("userspan").innerHTML="用户名不可用";
                }else {
                    document.getElementById("userspan").innerHTML="用户名可用";
                }
            }
        })
        }

        function tijiao(){
        var name=document.getElementsByName("name").values();
        var password=document.getElementsByName("password").values();

        $.ajax({
            type: "post",
            url: "login",
            data: {name:name,password:password},
            success:function (data){
                alert(data)
            }
        })
    }

    $(function (){
        $.get("queryall",{},function (data){
            var trs="";
            for(var i=0;i<data.length;i++){
                trs+="<tr>" +
                    "<td>"+data[i].username+"</td>" +
                    "<td>"+data[i].password+"</td>" +
                    "<td><a href='#' onclick='updUser("+data[i].id+")'>修改</a><a href='#' onclick='delUser("+data[i].id+")'>删除</a></td>" +
                    "</tr>"
            }
            $("#tb").html(trs);
        })
    })

    function updUser(id){

    }

    function delUser(id){}

</script>
<body>
name:<input type="text" name="name" onblur="checkUserName(this.value)"><span id="userspan" name="userspan"></span><br>
password:<input type="password" name="password"><br>
<input type="button" value="提交" onclick="tijiao()">

<table>
    <tr>
        <td>姓名</td>
        <td>密码</td>
        <td>操作</td>
    </tr>
    <tbody id="tb"></tbody>
</table>
</body>
</html>
